package com.xrjsj.stage.util;

import java.io.*;
import java.util.List;

/**
 * @author xurong
 * @since 2018/10/2 下午5:01
 */
public class CommonUtil {


    public static <T> List<T> deepCopy(List<T> src)  {
        ByteArrayOutputStream byteOut = null;
        ByteArrayInputStream byteIn = null;
        try{
            byteOut = new ByteArrayOutputStream();
            ObjectOutputStream out = new ObjectOutputStream(byteOut);
            out.writeObject(src);

            byteIn = new ByteArrayInputStream(byteOut.toByteArray());
            ObjectInputStream in = new ObjectInputStream(byteIn);
            List<T> dest = (List<T>) in.readObject();
            byteIn.close();
            byteOut.close();
            return dest;
        }catch (Exception e){
            e.printStackTrace();
            return null;
        }finally {
            try {
                if(byteIn != null){
                    byteIn.close();

                }
                if(byteOut != null){
                    byteOut.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }

        }



    }
}
